﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Wordprocessing;

namespace NFit.WordML
{
    public class WordElementContainer : IEnumerable<WordElementContainer>
    {
        public WordElementContainer Parent { get; private set; }

        public WordFileMapHierarchy Style { get; set; }

        public OpenXmlElement Element { get; private set; }

        private List<WordElementContainer> _childs = new List<WordElementContainer>();
        public List<WordElementContainer> Childs
        {
            get { return _childs; }
            set { _childs = value; }
        }

        public bool IsParagraph
        {
            get
            {
                return Element is Paragraph;
            }
        }

        public bool IsTable
        {
            get
            {
                return Element is Table;
            }
        }

        public WordElementContainer(OpenXmlElement element, WordFileMapHierarchy hierarchy)
        {
            Element = element;
            Style = hierarchy;
        }

        public WordElementContainer Add(OpenXmlElement child, WordFileMapHierarchy hierarchy)
        {
            var elt = new WordElementContainer(child, hierarchy);
            elt.Parent = this;
            Childs.Add(elt);
            return elt;
        }

        public IEnumerator<WordElementContainer> GetEnumerator()
        {
            return Childs.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return Childs.GetEnumerator();
        }
    }
}